home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / src_1218.zip / FILES.C < prev    next >
C/C++ Source or Header  |  1991-05-13  |  10KB  |  315 lines

  1. /* System-dependent definitions of various files, spool directories, etc */
  2. #include <stdio.h>
  3. #include "global.h"
  4. #include "netuser.h"
  5. #include "files.h"
  6.  
  7. #ifdef    MSDOS
  8. char *Startup = "/autoexec.net";    /* Initialization file */
  9. char *Userfile = "/ftpusers";    /* Authorized FTP users and passwords */
  10. char *Maillog = "/spool/mail.log";    /* mail log */
  11. char *Mailspool = "/spool/mail";    /* Incoming mail */
  12. char *Mailqdir = "/spool/mqueue";        /* Outgoing mail spool */
  13. char *Mailqueue = "/spool/mqueue/*.wrk";    /* Outgoing mail work files */
  14. char *Routeqdir = "/spool/rqueue";        /* queue for router */
  15. char *Alias = "/alias";        /* the alias file */
  16. char *Dfile = "/domain.txt";    /* Domain cache */
  17. char *Fdir = "/finger";        /* Finger info directory */
  18. char *Arealist = "/spool/areas";/* List of message areas */
  19. char *Helpdir = "/spool/help";    /* Mailbox help file directory */
  20. char *Rewritefile = "/spool/rewrite"; /* Address rewrite file */
  21. char *Newsdir = "/spool/news";        /* News messages and NNTP data */
  22. char *Popusers = "/popusers";        /* POP user and passwd file */
  23. char *Signature = "/spool/signatur"; /* Mail signature file directory */
  24. char *Forwardfile = "/spool/forward.bbs"; /* Mail forwarding file */
  25. char *Historyfile = "/spool/history"; /* Message ID history file */
  26. char Eol[] = "\r\n";
  27. #define    SEPARATOR    "/"
  28. #endif
  29.  
  30. #ifdef    UNIX
  31. char *Startup = "./startup.net";    /* Initialization file */
  32. char *Config = "./config.net";    /* Device configuration list */
  33. char *Userfile = "./ftpusers";
  34. char *Mailspool = "./mail";
  35. char *Maillog = "./mail.log";    /* mail log */
  36. char *Mailqdir = "./mqueue";
  37. char *Mailqueue = "./mqueue/*.wrk";
  38. char *Routeqdir = "./rqueue";        /* queue for router */
  39. char *Alias = "./alias";    /* the alias file */
  40. char *Dfile = "./domain.txt";    /* Domain cache */
  41. char *Fdir = "./finger";        /* Finger info directory */
  42. char *Arealist = "./areas";        /* List of message areas */
  43. char *Helpdir = "./help";    /* Mailbox help file directory */
  44. char *Rewritefile = "./rewrite"; /* Address rewrite file */
  45. char *Newsdir = "./news";        /* News messages and NNTP data */
  46. char *Popusers = "./popusers";        /* POP user and passwd file */
  47. char *Signature = "./signatur"; /* Mail signature file directory */
  48. char *Forwardfile = "./forward.bbs"; /* Mail forwarding file */
  49. char *Historyfile = "./history"; /* Message ID history file */
  50. #define    SEPARATOR    "/"
  51. char Eol[] = "\n";
  52. #endif
  53.  
  54. #ifdef    AMIGA
  55. char *Startup = "TCPIP:net-startup";
  56. char *Config = "TCPIP:config.net";    /* Device configuration list */
  57. char *Userfile = "TCPIP:ftpusers";
  58. char *Mailspool = "TCPIP:spool/mail";
  59. char *Maillog = "TCPIP:spool/mail.log";
  60. char *Mailqdir = "TCPIP:spool/mqueue";
  61. char *Mailqueue = "TCPIP:spool/mqueue/#?.wrk";
  62. char *Routeqdir = "TCPIP:spool/rqueue";        /* queue for router */
  63. char *Alias = "TCPIP:alias";    /* the alias file */
  64. char *Dfile = "TCPIP:domain.txt";    /* Domain cache */
  65. char *Fdir = "TCPIP:finger";        /* Finger info directory */
  66. char *Arealist = "TCPIP:spool/areas";    /* List of message areas */
  67. char *Helpdir = "TCPIP:spool/help";    /* Mailbox help file directory */
  68. char *Rewritefile = "TCPIP:spool/rewrite"; /* Address rewrite file */
  69. char *Newsdir = "TCPIP:spool/news";    /* News messages and NNTP data */
  70. char *Popusers = "TCPIP:/popusers";    /* POP user and passwd file */
  71. char *Signature = "TCPIP:spool/signatur"; /* Mail signature file directory */
  72. char *Forwardfile = "TCPIP:spool/forward.bbs"; /* Mail forwarding file */
  73. char *Historyfile = "TCPIP:spool/history"; /* Message ID history file */
  74. #define    SEPARATOR    "/"
  75. char Eol[] = "\r\n";
  76. #endif
  77.  
  78. #ifdef    MAC
  79. char *Startup ="Mikes Hard Disk:net.start";
  80. char *Config = "Mikes Hard Disk:config.net";    /* Device configuration list */
  81. char *Userfile = "Mikes Hard Disk:ftpusers";
  82. char *Mailspool = "Mikes Hard Disk:spool:mail:";
  83. char *Maillog = "Mikes Hard Disk:spool:mail.log:";
  84. char *Mailqdir = "Mikes Hard Disk:spool:mqueue:";
  85. char *Mailqueue = "Mikes Hard Disk:spool:mqueue:*.wrk";
  86. char *Routeqdir = "Mikes Hard Disk:spool/rqueue:";    /* queue for router */
  87. char *Alias = "Mikes Hard Disk:alias";    /* the alias file */
  88. char *Dfile = "Mikes Hard Disk:domain:txt";    /* Domain cache */
  89. char *Fdir = "Mikes Hard Disk:finger";        /* Finger info directory */
  90. char *Arealist = "Mikes Hard Disk:spool/areas";    /* List of message areas */
  91. char *Helpdir = "Mikes Hard Disk:spool/help"; /* Mailbox help file directory */
  92. char *Rewritefile = "Mikes Hard Disk:spool/rewrite"; /* Address rewrite file */
  93. char *Newsdir = "Mikes Hard Disk:spool/news"; /* News messages and NNTP data */
  94. char *Popusers = "Mikes Hard Disk:/popusers";    /* POP user and passwd file */
  95. char *Signature = "Mikes Hard Disk:spool/signatur"; /* Mail signature file directory */
  96. char *Forwardfile = "Mikes Hard Disk:spool/forward.bbs"; /* Mail forwarding file */
  97. char *Historyfile = "Mikes Hard Disk:spool/history"; /* Message ID history file */
  98. #define    SEPARATOR    ":"
  99. char Eol[] = "\r";
  100. #endif
  101.  
  102. static char *rootdir = "";
  103.  
  104. /* Establish a root directory other than the default. Can only be called
  105.  * once, at startup time
  106.  */
  107. void
  108. initroot(root)
  109. char *root;
  110. {
  111.     rootdir = strdup( root );
  112.  
  113.     Startup = rootdircat(Startup);
  114.     Userfile = rootdircat(Userfile);
  115.     Maillog = rootdircat(Maillog);
  116.     Mailspool = rootdircat(Mailspool);
  117.     Mailqdir = rootdircat(Mailqdir);
  118.     Mailqueue = rootdircat(Mailqueue);
  119.     Routeqdir = rootdircat(Routeqdir);
  120.     Alias = rootdircat(Alias);
  121.     Dfile = rootdircat(Dfile);
  122.     Fdir = rootdircat(Fdir);
  123.     Arealist = rootdircat(Arealist);
  124.     Helpdir = rootdircat(Helpdir);
  125.     Rewritefile = rootdircat(Rewritefile);
  126.     Newsdir = rootdircat(Newsdir);
  127.     Signature = rootdircat(Signature);
  128.     Forwardfile = rootdircat(Forwardfile);
  129.     Historyfile = rootdircat(Historyfile);
  130. }
  131.  
  132. /* Concatenate root, separator and arg strings into a malloc'ed output
  133.  * buffer, then remove repeated occurrences of the separator char
  134.  */
  135. char *
  136. rootdircat(filename)
  137. char *filename;
  138. {
  139.     char *out = filename;
  140.  
  141.     if ( strlen(rootdir) > 0 ) {
  142.         char *separator = SEPARATOR;
  143.  
  144.         out = mallocw( strlen(rootdir)
  145.                 + strlen(separator)
  146.                 + strlen(filename) + 1);
  147.  
  148.         strcpy(out,rootdir);
  149.         strcat(out,separator);
  150.         strcat(out,filename);
  151.         if(*separator != '\0'){
  152.             char *p1, *p2;
  153.  
  154.             /* Remove any repeated occurrences */
  155.             p1 = p2 = out;
  156.             while(*p2 != '\0'){
  157.                 *p1++ = *p2++;
  158.                 while(p2[0] == p2[-1] && p2[0] == *separator)
  159.                     p2++;
  160.             }
  161.             *p1 = '\0';
  162.         }
  163.     }
  164.     return out;
  165. }
  166.  
  167. /* Read through FTPUSERS looking for user record
  168.  * Returns line which matches username, or NULLCHAR when no match.
  169.  * Each of the other variables must be copied before freeing the line.
  170.  */
  171. char *
  172. userlookup(username,password,directory,permission,ip_address)
  173. char *username;
  174. char **password;
  175. char **directory;
  176. int   *permission;
  177. int32 *ip_address;
  178. {
  179.     FILE *fp;
  180.     char *buf;
  181.     char *cp;
  182.  
  183.     if((fp = fopen(Userfile,READ_TEXT)) == NULLFILE)
  184.         /* Userfile doesn't exist */
  185.         return NULLCHAR;
  186.  
  187.     buf = mallocw(128);
  188.     while ( fgets(buf,128,fp) != NULLCHAR ){
  189.         if(*buf == '#')
  190.             continue;    /* Comment */
  191.  
  192.         if((cp = strchr(buf,' ')) == NULLCHAR)
  193.             /* Bogus entry */
  194.             continue;
  195.         *cp++ = '\0';        /* Now points to password */
  196.  
  197.         if( stricmp(username,buf) == 0 )
  198.             break;        /* Found user */
  199.     }
  200.     if(feof(fp)){
  201.         /* username not found in file */
  202.         fclose(fp);
  203.         free(buf);
  204.         return NULLCHAR;
  205.     }
  206.     fclose(fp);
  207.  
  208.     if ( password != NULL )
  209.         *password = cp;
  210.  
  211.     /* Look for space after password field in file */
  212.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  213.         /* Invalid file entry */
  214.         free(buf);
  215.         return NULLCHAR;
  216.     }
  217.     *cp++ = '\0';    /* Now points to directory field */
  218.  
  219.     if ( directory != NULL )
  220.         *directory = cp;
  221.  
  222.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  223.         /* Permission field missing */
  224.         free(buf);
  225.         return NULLCHAR;
  226.     }
  227.     *cp++ = '\0';    /* now points to permission field */
  228.  
  229.     if ( permission != NULL )
  230.         *permission = (int)strtol( cp, NULLCHARP, 0 );
  231.  
  232.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  233.         /* IP address missing */
  234.         if ( ip_address != NULL )
  235.             *ip_address = 0L;
  236.     } else {
  237.         *cp++ = '\0';    /* now points at IP address field */
  238.         if ( ip_address != NULL )
  239.             *ip_address = resolve( cp );
  240.     }
  241.     return buf;
  242. }
  243.  
  244. /* Subroutine for logging in the user whose name is name and password is pass.
  245.  * The buffer path should be long enough to keep a line from the userfile.
  246.  * If pwdignore is true, the password check will be overridden.
  247.  * The return value is the permissions field or -1 if the login failed.
  248.  * Path is set to point at the path field, and pwdignore will be true if no
  249.  * particular password was needed for this user.
  250.  */
  251. int
  252. userlogin(name,pass,path,len,pwdignore)
  253. char *name;
  254. char *pass;
  255. char **path;
  256. int len;            /* Length of buffer pointed at by *path */
  257. int *pwdignore;
  258. {
  259.     char *buf;
  260.     char *password;
  261.     char *directory;
  262.     int permission;
  263.     int anonymous;
  264.     char *cp;
  265.     if ( (buf = userlookup( name, &password, &directory,
  266.             &permission, NULL )) == NULLCHAR ) {
  267.         return -1;
  268.     }
  269.  
  270.     anonymous = *pwdignore;
  271.     if ( strcmp(password,"*") == 0 )
  272.         anonymous = TRUE;    /* User ID is password-free */
  273.  
  274.     if(!anonymous && strcmp(password,pass) != 0) {
  275.         /* Password required, but wrong one given */
  276.         free(buf);
  277.         return -1;
  278.     }
  279.  
  280.     if ( strlen( directory ) + 1 > len ) {
  281.         /* not enough room for path */
  282.         free(buf);
  283.         return -1;
  284.     }
  285.  
  286. #if   defined(AMIGA)
  287.     /*
  288.      * Well, on the Amiga, a file can be referenced by many names:
  289.      * device names (DF0:) or volume names (My_Disk:).  This hunk of code
  290.      * passed the pathname specified in the ftpusers file, and gets the
  291.      * absolute path copied into the user's buffer.  We really should just
  292.      * allocate the buffer and return a pointer to it, since the caller
  293.      * really doesn't have a good idea how long the path string is..
  294.      */
  295.     if ( (directory = pathname("", directory)) != NULLCHAR ) {
  296.         strcpy(*path, directory);
  297.         free(directory);
  298.     } else {
  299.         **path = '\0';
  300.     }
  301. #else
  302.     strcpy(*path,directory);
  303.     /* Convert any backslashes to forward slashes, for backward
  304.      * compatibility with the old NET
  305.      */
  306.     while((cp = strchr(*path,'\\')) != NULLCHAR)
  307.         *cp = '/';
  308. #endif
  309.     free(buf);
  310.     *pwdignore = anonymous;
  311.     /* Finally return the permission bits */
  312.     return permission;
  313. }
  314.  
  315.